package LeetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}22:15
 */
public class LeetCode39 {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> combinationSum(int[] candidates, int target) {
        if (candidates.length == 0){
            return res;
        }
        List<Integer> liat = new ArrayList<>();
        getNums(candidates,target,liat,0);
        return res;
    }

    public void getNums(int[] candidates,int target,List<Integer> list,int begin){
        if (target == 0){
            res.add(new ArrayList<>(list));
            return;
        }
        for (int i = begin; i < candidates.length; i++){

            if (candidates[i] > target){
                continue;
            }
            target -= candidates[i];
            list.add(candidates[i]);
            getNums(candidates,target,list,i);
            target += candidates[i];
            list.remove(list.size() - 1);
        }
    }

    public static void main(String[] args) {
        System.out.println(new LeetCode39().combinationSum(new int[]{2, 3, 5}, 7));
    }
}
